package com.jbp.controller;

import com.jbp.model.UserLocation;
import com.jbp.service.UserLocationService;
import com.jbp.utils.PageUtils;
import com.jbp.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * (UserLocation)表控制层
 * @author cc
 * @since 2021-09-16 17:18:22
 */
@Api(tags ="APP接口--UserLocation" )
@RestController
@RequestMapping("rest/userLocation")
public class UserLocationController {
    @Autowired
    private UserLocationService userLocationService;

    /** 附近的人 */
    @ApiOperation(value="列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = UserLocation.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/nearby")
    public R nearby(@RequestParam Map<String, Object> params,@RequestAttribute("userId") Integer userId){
        PageUtils page = userLocationService.nearby(params, userId);
        return R.ok().put("page", page);
    }

    /** 保存 */
    @PostMapping("/save")
    public R save(@RequestBody UserLocation userLocation, @RequestAttribute("userId") Integer userId){
        if (userLocation.getLng()==null || userLocation.getLat()==null){
            return R.error("经纬度为空");
        }
        userLocation.setUserId(userId);
        userLocationService.add(userLocation);
        return R.ok();
    }

}